package com.example.demo.common;

import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public abstract class BaseService<T extends BaseEntity, D extends BaseDao<T>> {

    @Autowired
    protected D dao;

    public T get(String id) {
        return dao.get(id);
    }

    public List<T> find(T t) {
        return dao.find(t);
    }

    public Pagination pagination(HttpServletRequest request, T t) {
        Pagination pagination = new Pagination(request);
        try {
            t.setPagination(pagination);
            pagination.setData(dao.find(t));
            return pagination.yes();
        } catch (Exception e) {
            e.printStackTrace();
            return pagination.no();
        }
    }

}
